<template>
  <div class='xtx-goods-page' v-if="goods">
    <div class="container">
      <!-- 面包屑 -->
      <XtxBread>
        <XtxBreadItem to="/">首页</XtxBreadItem>
        <XtxBreadItem :to="`/category/${goods.categories[1].id}`">{{goods.categories[1].name}}</XtxBreadItem>
        <XtxBreadItem :to="`/category/sub/${goods.categories[0].id}`">{{goods.categories[0].name}}</XtxBreadItem>
        <XtxBreadItem to="/">{{goods.name}}</XtxBreadItem>
      </XtxBread>
      <!-- 商品信息 -->
      <div class="goods-info">
     <!-- 图片预览区 -->

    <div class="media">
        <XtxImageView :imageList="goods.mainPictures" />
    <GoodsSale :goods="goods" />

    </div>
    <!-- 商品信息区 -->
    <div class="spec">
        <GoosInfo :goods="goods" />
        <!-- 商品规格组件 -->
        <XtxGoodSku :goods="goods" :skuId="''" @change="goodsskuchangeFn"></XtxGoodSku>
        <!-- 商品选择数量组件 -->
        <XtxNumbox v-model="count" :min='1' :max="goods.inventory"></XtxNumbox>
        <!-- 加入购物车 -->
        <XtxButton  @click="addToCart" type="primary" style="margin-top: 20px;">加入购物车</XtxButton>
    </div>
      </div>
      <!-- 商品详情 -->
      <div class="goods-footer">
        <div class="goods-article">
          <!-- 商品+评价 -->
          <div class="goods-tabs">
              <GoodsDetail :goods="goods"></GoodsDetail>
          </div>
        </div>
        <!-- 24热榜+专题推荐 -->
        <div class="goods-aside">
            <GoodsHot :goodsId="goods.id" type="1"></GoodsHot>
            <GoodsHot :goodsId="goods.id" type="2"></GoodsHot>
            <GoodsHot :goodsId="goods.id" type="3"></GoodsHot>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { useRoute } from 'vue-router'
import { findGoods } from '@/api/goods'
import { ref } from 'vue-demi'
import GoosInfo from './components/goods-info.vue'
import GoodsSale from './components/goods-sale.vue'
import GoodsDetail from './components/goods-detail.vue'
import GoodsHot from './components/goods-hot.vue'
export default {
  components: {
    GoosInfo,
    GoodsSale,
    GoodsDetail,
    GoodsHot
  },
  name: 'XtxGoodsPage',
  setup () {
    const goods = ref()
    const route = useRoute()
    findGoods(route.params.id).then(({ result }) => {
      console.log('详情', result)
      goods.value = result
    })
    // 选择收货地址
    const changeFn = (val) => {
      console.log('城市', val)
    }
    // 选择商品规格
    const goodsskuchangeFn = (val) => {
      // 点击修改规格
      if (val.skuId) {
        for (const key in val) {
          goods.value[key] = val[key]
        }
      }
    }
    // 商品数量
    const count = ref(1)
    // 加入购物车
    const addToCart = () => {
      alert('加入购物车成功')
    }

    return { goods, changeFn, goodsskuchangeFn, count, addToCart }
  }
}
</script>

<style scoped lang='less'>
.goods-info {
  min-height: 600px;
  background: #fff;
}
.goods-footer {
  display: flex;
  margin-top: 20px;
  .goods-article {
    width: 940px;
    margin-right: 20px;
  }
  .goods-aside {
    width: 280px;
    min-height: 1000px;

  }
}
.goods-tabs {
  min-height: 600px;
  background: #fff;
}
.goods-warn {
  min-height: 600px;
  background: #fff;
  margin-top: 20px;
}
//图片详情
 .goods-info {
      min-height: 600px;
      background: #fff;
      display: flex;
      .media {
        width: 580px;
        height: 600px;
        padding: 30px 50px;
      }
      .spec {
        flex: 1;
        padding: 30px 30px 30px 0;
      }
    }
</style>
